// pages/awardWinning/awardWinning.js
const bgSpeed = 2;
const topSpeed = 1.5;

let windowWidth = 0;
let windowHeight = 0;

let scrollLeft;

let imgNum = 0;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bgScroll: 0,
    middleScroll: 0,
    topScroll: 0,
    popShow: false,
    imgScale: 1,
    imgUrl: '',
    isHeight: false,

    loadingShow: true
  },

  imageLoaded(e) {
    imgNum ++;
    if (imgNum == 54) {
      this.setData({
        loadingShow: false
      })
    }
  },

  sliderChange(e) {
    let num = e.detail.value, imgScale = 1;
    imgScale = num/100*2 + 1;
    this.setData({
      imgScale
    })
  },

  popCloseTap(e) {
    this.setData({
      imgScale: 1,
      popShow: false,
    })
  },

  showProductTap(e) {
    console.log(e.currentTarget.id);
    let id = e.currentTarget.id, imgUrl = '', isHeight = false;
    imgUrl = 'https://evanbuckt.oss-cn-shanghai.aliyuncs.com/uob_art/aw_product_img'+ id +'.jpg'
    if (id == 0 || id == 1 || id == 5 || id == 14) {
      isHeight = true
    }
    this.setData({
      popShow: true,
      imgUrl,
      isHeight
    })
  },

  itemRollFun(id,obj) {
    let that = this, num = 0;
    wx.createSelectorQuery().select(id).boundingClientRect(function (res) {
      if (res.left > windowWidth || res.left < 0 - res.width) return;
      num = (res.left+res.width/2 - windowWidth/2)/5*-1;
      if (num<=-20){
        num = -20
      }else if(num>=20){
        num = 20
      }
      that.setData({
        [obj]: num
      })
    }).exec();
  },

  scrollFun(e) {
    //scrollLeft = e.detail.scrollLeft;

    for (let i=0;i<14;i++) {
      this.itemRollFun('#awItem'+i,'awItemDeg'+i);
    }
    
    // this.setData({
    //   bgScroll: scrollLeft/bgSpeed,
    //   middleScroll: scrollLeft,
    //   topScroll: scrollLeft*topSpeed,
    // })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const query = wx.createSelectorQuery();
    const element=query.selectViewport();
    element.boundingClientRect(function (res) {
      windowWidth = res.width;
      windowHeight = res.height;
    }).exec();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})